(define-module (wigust packages games)
  #:use-module (ice-9 match)
  #:use-module ((guix licenses) #:prefix license:)
  #:use-module (guix utils)
  #:use-module (guix packages)
  #:use-module (guix download)
  #:use-module (guix git-download)
  #:use-module (guix gexp)
  #:use-module (gnu packages)
  #:use-module (gnu packages compression)
  #:use-module (gnu packages games)
  #:use-module (gnu packages sdl)
  #:use-module (gnu packages fontutils)
  #:use-module (gnu packages xorg)
  #:use-module (gnu packages perl)
  #:use-module (guix build-system trivial))

(define-public stb
  (let ((commit "9d9f75eb682dd98b34de08bb5c489c6c561c9fa6")
        (revision "1"))
    (package
      (name "stb")
      (version (string-append "0.0.1-" revision "."
                              (string-take commit 7)))
      (source
       (origin
         (method git-fetch)
         (uri (git-reference
               (url "git://github.com/nothings/stb.git")
               (commit commit)))
         (file-name (string-append name "-" version "-checkout"))
         (sha256
          (base32
           "0q84bl6ai2mrcywrynvqvvlr6dpyafx33j3xaz6n38z5gi8lcmzx"))))
      (build-system trivial-build-system)
      (inputs `(("source" ,source)))
      (arguments
       `(#:modules
         ((guix build utils))
         #:builder
         (begin
           (use-modules (guix build utils))
           (for-each (lambda (file)
                       (install-file file (string-append %output
                                                         "/include/stb")))
                     (find-files (assoc-ref %build-inputs "source")
                                 "\\.h$")))))
      (home-page "https://github.com/nothings/stb")
      (synopsis "stb single-file public domain libraries for C/C++")
      (description "stb single-file public domain libraries for C/C++")
      (license license:expat))))

(define-public angband-nonfree
  ;; TODO: Sound, X11.
  (package
    (inherit angband)
    (name "angband-nonfree")
    (version "4.1.0")
    (source
     (origin
       (method url-fetch)
       (uri (string-append "http://rephial.org/downloads/4.1/"
                           "angband-" version ".tar.gz"))
       (sha256
        (base32
         "0vhvzbrm6hwca2yp02pg2vzg4c5yf65whg0bmjbalmhy1r4kw51x"))))
    (inputs
     `(("sdl-union" ,(sdl-union (list sdl sdl-image sdl-mixer sdl-ttf)))
       ("freetype" ,freetype)
       ("libx11" ,libx11)
       ("perl" ,perl)
       ,@(package-inputs angband)))
    (arguments
     `(#:tests?
       #f
       #:configure-flags
       (list (string-append "--bindir=" %output "/bin")
             (string-append "--sysconfdir=" %output "/share/angband")
             "--enable-sdl" "CFLAGS=-fgnu89-inline" "--enable-sdl-mixer")
       #:phases
       (modify-phases %standard-phases
         (add-after 'unpack 'autogen.sh
           (lambda _
             (zero? (system* "sh" "autogen.sh"))
             (substitute* "src/main-sdl.c" (("SDL_ttf.h") "SDL/SDL_ttf.h"))
             (substitute* "src/main-sdl.c" (("SDL_image.h") "SDL/SDL_image.h"))
             #t)))))))

;; TODO: Update to new version to have a sound support
(define-public cataclysm-dda-chesthole
  (package
    (name "cataclysm-dda-chesthole")
    (version "0")
    (build-system trivial-build-system)
    (source (origin
              (method url-fetch/zipbomb)
              (uri (string-append "http://chezzo.com/cdda/catasounds" ".zip"))
              (sha256
               (base32
                "195kwyldahkscm2cpchxylrf3rv83h95f1kw8287iwnscw1bdzbd"))))
    (native-inputs
     `(("unzip" ,unzip)))
    (propagated-inputs
     `(("cataclysm-dda" ,cataclysm-dda)))
    (arguments
     `(#:modules
       ((guix build utils))
       #:builder
       (begin
         (use-modules (guix build utils))
         (let ((cataclysm-dda (string-append (assoc-ref %outputs "out")
                                             "/share/cataclysm-dda")))
           (copy-recursively (assoc-ref %build-inputs "source") cataclysm-dda)
           (with-output-to-file (string-append cataclysm-dda "/sound/soundpack.txt")
                          (lambda ()
                            (display "#chesthole soundpack
#Name of the soundpack
NAME: chesthole
#Viewing name of the soundpack
VIEW: chesthole\n")))
           #t))))
    (synopsis "Static site data for Haunt")
    (description "This package provides statis data like CSS and JS for blog.")
    (license #f)
    (home-page #f)))

;; (define-public cataclysm-dda-catasounds
;;   (inherit cataclysm-dda)
;;   (name "cataclysm-dda-catasounds")
;;   (arguments
;;    (substitute-keyword-arguments (package-arguments cataclysm-dda)
;;      ((#:phases phases)
;;       `(modify-phases ,phases
;;          (add-after 'install 'install-sound
;;            (lambda* (#:key outputs #:allow-other-keys)
;;              (string-append (assoc-ref outputs "tiles")
;;                             "/share/cataclysm-dda/sound"))))))))
